import java.util.Arrays;

public class test {
    public static void main(String[] args) {
        //int[] array = {1,6,2,3,8,9,4,5,11,7,23};
        int[] array = {3,1,2,4,5,6,7,8,9,10};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void bubbleSort(int[] elem) {
        int len = elem.length;
        boolean flg = true;//true代表有序
        for (int i = 0; i < len-1; i++) {
            flg = true;//每一趟之前，假设有序
            for (int j = 0; j < len-1-i; j++) {
                if(elem[j] > elem[j+1]) {
                    flg = false;//一旦进入if语句，说明不是有序
                    int tmp = elem[j];
                    elem[j] = elem[j+1];
                    elem[j+1] = tmp;
                }
            }
            if(flg) {
                return;
            }
        }
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        int[] arr = {11,22,33,44,5};
        System.arraycopy(arr,0,array,0,4);
        System.out.println(Arrays.toString(array));
    }
}
